package com.shanxia.codec.cmd;

import com.shanxia.codec.ProtocolDataBase;
import com.shanxia.codec.enums.DecodeEnum;
import lombok.Data;

import static com.shanxia.codec.Decoder.getUint8;

/**
 * C -> S
 * 充电桩应答后台服务器设置 24 时电费计价策略
 */
@Data
public class Cmd1104 extends ProtocolDataBase {

    public static final int MIN_SIZE = 1;

    private int code;				// 确认结果

	public Cmd1104(){
		super.setCmd(1104);
	}

	public static Cmd1104 decodeFromBase(ProtocolDataBase protocolDataBase) {
		Cmd1104 cmd = new Cmd1104();
		cmd.copyDataFrom(protocolDataBase);
		byte[] dataField = protocolDataBase.getDataField();
		//数据域长度
		if(dataField.length < MIN_SIZE) {
			cmd.setResult(DecodeEnum.InvalidData);
			return cmd;
		}
		// 1字节确认结果
		cmd.code = getUint8(dataField[0]);
		return cmd;
	}

	@Override
	public String toString() {

		StringBuffer buffer = new StringBuffer();
		buffer.append("#cmd1104#").append("\n");
		buffer.append("确认结果:").append(code).append("\n");
		return buffer.toString();
	}
}
